﻿@{
    ViewBag.Title = "商品采购管理";
    Layout = "~/Views/Shared/_ListLayout.cshtml";
}
@section toolbar{
}
@section script
{
    <script type="text/javascript">
        mini.parse();
        function showSearchWindow() {
            var win = mini.get("searchWindow");
            win.show();
        }
        var tree = mini.get("tree1");
        tree.on("nodeselect", function (e) {
            if (e.isLeaf) {
                advSearch();
            } else {
                grid.setData([]);
                grid.setTotalCount(0);
            }
        });
        function treesearch() {
            var value = mini.get("treekey").getValue();
            tree.load("/Archives/SearchAllranches/" + value);
        }
        function advSearch() {
            var frm = new mini.Form("frmAdv");
            var data = frm.getData(true);
            data.bCode = tree.getSelectedNode().Id;
            grid.load(data);
            var win = mini.get("searchWindow");
            win.hide();
        }
        function search() {
            grid.load({
                "key": mini.get("#key").value,
                dates: mini.get("dateS").getFormValue(),
                datee: mini.get("dateE").getFormValue()
            });
        }
        function editRow(id) {
            var eUrl = "/Business/PurchaseEdit/" + id + "?bCode=";
            if (tree.getSelectedNode()) {
                eUrl += tree.getSelectedNode().Id;
            }
            mini.open({
                url: eUrl,
                title: "采购管理",
                iconCls: "icon-cart",
                allowResize: false,
                width: 760,
                height: 500,
                onload: function () {
                },
                ondestroy: function (action) {

                    grid.reload();
                }
            });
        }
        function viewItem(id) {
            var eUrl = "/Query/PurchaseView/" + id + "?bCode=";
            if (tree.getSelectedNode()) {
                eUrl += tree.getSelectedNode().Id;
            }
            mini.open({
                url: eUrl,
                title: "订单查看",
                iconCls: "icon-cart",
                allowResize: false,
                width: 700,
                height: 500,
                onload: function () {
                },
                ondestroy: function (action) {

                    grid.reload();
                }
            });
        }
        function deleteItem(id) {
            $.ajax({
                url: "/Business/PurchaseDelete",
                data: { ids: id },
                success: function (text) {
                    grid.reload();
                },
                error: function () {
                }
            });
        }
        function onActionColRenderer(e) {
            var grid = e.sender;
            var record = e.record;
            var uid = record.Id;
            var rowIndex = e.rowIndex;
            if (record.IfExamine) {
                if (record.IfExamine == "true" || record.IfExamine == "1") {
                    var s = ' <a class="Edit_Button" href="javascript:viewItem(\'' + uid + '\')" >查看</a>'
                         + ' <a class="Edit_Button" href="javascript:viewItem(\'' + uid + '\')" >打印</a>';
                    return s;
                }
            }

            var s = ' <a class="Edit_Button" href="javascript:editRow(\'' + uid + '\')" >编辑</a>'
                + ' <a class="Delete_Button" href="javascript:if(confirm(\'确定要删除这条记录吗？\')){deleteItem(\'' + uid + '\')}">删除</a>';
            return s;
        }
        function exame(obj, itemid, old) {
            $.ajax({
                url: "/Business/PurchaseExame/" + itemid,
                success: function (j) {
                    if (j == true) {
                        $(obj).css("color", "green").text("是");
                    }
                    else {
                        $(obj).css("color", "red").text("否");
                    }
                    $(obj).removeProp("onclick");
                    $(obj).unbind("click").click(function () {
                        exame(obj, itemid, !old)
                    })
                },
                error: function () {
                    alert("失败")
                }
            });
        }
    </script>
}
<div class="mini-splitter" style="width: 100%; height: 100%;">
    <div size="240" showcollapsebutton="true">
        <div class="mini-toolbar" style="padding: 2px; border-top: 0; border-left: 0; border-right: 0;">
            <input class="mini-textbox" id="treekey" style="width: 150px;" />
            
            <a class="mini-button" iconcls="icon-search" plain="true" onclick="treesearch">查找</a>
        </div>
        <div class="mini-fit">
            <ul id="tree1" class="mini-tree" url="/Archives/SearchAllranchesForTree" style="width: 100%;"
                showtreeicon="true" textfield="bName" idfield="Id" parentfield="pid" resultastree="false">
            </ul>
        </div>
    </div>
    <div showcollapsebutton="true" id="printArea">
        <div style="width: 100%">
            <div class="mini-toolbar" style="border-bottom: 0; padding: 0px;">
                <table style="width: 100%;">
                    <tr>
                        <td style="width: 100%;">
                            <a class="mini-button" iconcls="icon-add" onclick="editRow('')" plain="true">增加</a>
                            @*<a class="mini-button" iconcls="icon-remove" onclick="remove()" plain="true">删除</a>
                            <a class="mini-button" iconcls="icon-date-magnify" onclick="showSearchWindow()" plain="true">
                                筛选</a> <span class="separator"></span>*@
                        </td>
                        <td style="white-space: nowrap;">
                            <input id="dateS" class="mini-datepicker" value="@DateTime.Now.ToString("yyyy-MM-01")" emptytext="开始时间" />
                            ~<input id="dateE" class="mini-datepicker" value="@Convert.ToDateTime(DateTime.Now.AddMonths(1).ToString("yyyy-MM-01")).AddDays(-1).ToString("yyyy-MM-dd")" emptytext="结束时间" />
                            <input id="key" class="mini-textbox" emptytext="请输入关键词" style="width: 150px;" onenter="onKeyEnter" />
                            <a class="mini-button" onclick="search()">查询</a>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div id="datagrid1" class="mini-datagrid" url="/Business/SearchPurchaseList" style="width: 100%;
            height: 95%;" idfield="id" allowresize="false" sizelist="[20,30,50,100]" pagesize="20"
            multiselect="true" showpager="true">
            <div property="columns">
                <div type="indexcolumn" width="30">
                </div>
                <div type="checkcolumn" width="30">
                </div>
                <div field="Id" headeralign="center" align="center" width="100">
                    单号</div>
                @if (TEWorkFlow.Web.Client.Common.MyEnv.IsEmployeeLogin)
                {
                <div field="SupCode" headeralign="center" align="center" width="60">
                    供货商</div>
                }
                <div field="bName" headeralign="center" align="center" width="60">
                    门店名称</div>
                <div field="PcType" headeralign="center" align="center" width="60">
                    采购类型</div>
                <div field="PurchaseDate" headeralign="center" align="center" width="60" dateformat="yyyy-MM-dd">
                    采购日期</div>
                <div field="amount" headeralign="center" align="center" width="60" datatype="currency"
                    currencyunit="￥">
                    价格</div>
                <div field="IfExamine" headeralign="center" align="center" width="40" renderer="onExamRender">
                    审核</div>
                <div name="action" width="30" headeralign="center" align="center" renderer="onActionColRenderer"
                    cellstyle="padding:0;">
                    管理</div>
            </div>
        </div>
    </div>
</div>
<div id="searchWindow" class="mini-window" title="高级筛选" style="width: 450px; height: 180px;"
    iconcls="icon-date-magnify" showmaxbutton="true" showtoolbar="true" showfooter="true"
    showmodal="false" allowresize="false" allowdrag="true">
    <div property="footer" style="text-align: right; padding: 5px; padding-right: 15px;">
        <a class="mini-button" iconcls="icon-zoom" onclick="advSearch()" style='vertical-align: middle;'>
            筛选</a>
    </div>
    <form id="frmAdv">
    <table class="edittable" border="1" cellpadding="0" cellspacing="0">
        <tr>
            <td style="width: 60px;">
                采购单号:
            </td>
            <td style="width: 140px;">
                <input name="Id" class="mini-textbox" />
            </td>
            <td style="width: 60px;">
                供货商:
            </td>
            <td style="width: 140px;">
                <input name="SupCode" class="mini-autocomplete" require="true" valuefield="SupName"
                    displayfield="SupName" url="/Archives/GetAllSupplierArchive" onvaluechanged="onSupCodeValueChanged" />
            </td>
        </tr>
        <tr>
            <td style="width: 60px;">
                采购形式:
            </td>
            <td style="width: 140px;">
                <input name="PcForm" class="mini-textbox" />
            </td>
            <td style="width: 60px;">
                门店:
            </td>
            <td style="width: 140px;">
                <input name="bCode" class="mini-combobox" textfield="bName" valuefield="Id" emptytext="请选择..."
                    url="/Archives/SearchAllranches" allowinput="false" shownullitem="true" nullitemtext="请选择..." />
            </td>
        </tr>
        <tr>
            <td style="width: 60px;">
                采购类型:
            </td>
            <td style="width: 140px;">
                <input name="PcType" class="mini-combobox" textfield="text" valuefield="id" emptytext="请选择..."
                    url="/Category/PcType" allowinput="false" shownullitem="true" nullitemtext="请选择..." />
            </td>
            <td style="width: 60px;">
                采购方式:
            </td>
            <td style="width: 140px;">
                <input name="PcMode" class="mini-combobox" textfield="text" valuefield="id" emptytext="请选择..."
                    url="/Category/PcMode" allowinput="false" shownullitem="true" nullitemtext="请选择..." />
            </td>
        </tr>
    </table>
    </form>
</div>
